Skip to content

Handle invalid stdio JSON-RPC requests without leaving clients waiting#1795

Closed
raashish1601 wants to merge 2 commits intomodelcontextprotocol:mainfrom
raashish1601:contributor-08/typescript-sdk-1765
Closed

Handle invalid stdio JSON-RPC requests without leaving clients waiting#1795
raashish1601 wants to merge 2 commits intomodelcontextprotocol:mainfrom
raashish1601:contributor-08/typescript-sdk-1765

Conversation

@raashish1601
Copy link
Copy Markdown

Fixes #1765.

Summary

  • classify schema-invalid stdio input as a dedicated invalid-JSON-RPC decode error instead of a generic validation failure
  • have StdioServerTransport emit an Invalid Request JSON-RPC error response for those malformed request lines and then continue processing subsequent input
  • add focused coverage for unsafe numeric request ids and for the stdio transport continuing to read after replying with the invalid-request error

Validation

  • corepack pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/stdio.test.ts
  • corepack pnpm --filter @modelcontextprotocol/server exec vitest run test/server/stdio.test.ts
  • corepack pnpm --filter @modelcontextprotocol/core run typecheck
  • corepack pnpm --filter @modelcontextprotocol/server run typecheck
  • corepack pnpm exec prettier --check packages/core/src/shared/stdio.ts packages/core/test/shared/stdio.test.ts packages/server/src/server/stdio.ts packages/server/test/server/stdio.test.ts
  • corepack pnpm exec eslint src/shared/stdio.ts test/shared/stdio.test.ts (from packages/core)
  • corepack pnpm exec eslint src/server/stdio.ts test/server/stdio.test.ts (from packages/server)

Notes

  • the repo-level pnpm --filter ... run lint commands still fail on existing package-wide Prettier drift in untouched files, so validation stayed focused to the touched files plus the relevant typechecks and tests.

@raashish1601 raashish1601 requested a review from a team as a code owner March 27, 2026 18:56
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 27, 2026

🦋 Changeset detected

Latest commit: 4e18bce

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@modelcontextprotocol/core Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/node Patch
@modelcontextprotocol/express Patch
@modelcontextprotocol/hono Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 27, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1795

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1795

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1795

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1795

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1795

commit: 4e18bce

@felixweinberger
Copy link
Copy Markdown
Contributor

Per discussion on #1765: precision loss happens at JSON.parse before the SDK sees the value, so this isn't SDK-fixable. Clients should use string IDs for large values. Closing pending confirmation on the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server hangs indefinitely when JSON-RPC request ID exceeds

2 participants